package org.zcl.集合;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Package org.zcl.集合
 * @PROJECT_NAME: question
 * @DESCRIPTION:
 * @USER: zhuchenglin
 * @DATE: 2021/12/29 16:58
 */
public class AnyMatchDemo {
    public static void main(String[] args) {
        List<String> list1 = Arrays.asList("1","2");
        List<String> list2 = Arrays.asList("1","3");
        boolean result = false;
        for (String s : list2) {
            if (list1.contains(s)) {
                result = true;
                break;
            }
        }
        System.out.println(result);

        // java8
        result = list2.stream().anyMatch(list1::contains);
        System.out.println(result);

        // 创建一个动态数组
        ArrayList<String> sites = new ArrayList<>();

        sites.add("Google");
        sites.add("Runoob");
        sites.add("Taobao");

        System.out.println("ArrayList 1: " + sites);

        // 创建另一个动态数组
        ArrayList<String> sites2 = new ArrayList<>();

        // 往动态数组中添加元素
        sites2.add("Wiki");
        sites2.add("Runoob");
        sites2.add("Google");
        System.out.println("ArrayList 2: " + sites2);

        // 保留元素
        sites.retainAll(sites2);
        System.out.println("保留的元素: " + sites);
    }
}
